{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "import pandas as pd\n",
    "sys.path.append(os.path.abspath('../script'))\n",
    "from AB_hypothesis_testing import ABHypothesisTesting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Abeni\\AppData\\Local\\Temp\\ipykernel_13776\\3505119952.py:2: DtypeWarning: Columns (4,31) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  data = pd.read_csv('../src/data/cleaned_data.csv')\n"
     ]
    }
   ],
   "source": [
    "# Load your data\n",
    "data = pd.read_csv('../src/data/cleaned_data.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Null Hypothesis: There are no risk differences across provinces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chi-squared test for provinces: p-value = 1.0\n",
      "Fail to reject the null hypothesis: There are no significant risk differences across provinces.\n"
     ]
    }
   ],
   "source": [
    "# Null Hypothesis: There are no risk differences across provinces\n",
    "try:\n",
    "    province_p_value = analyzer.chi_squared_test('Province', 'TotalClaims')\n",
    "    print(f\"Chi-squared test for provinces: p-value = {province_p_value}\")\n",
    "    if province_p_value < 0.05:\n",
    "        print(\"Reject the null hypothesis: There are significant risk differences across provinces.\")\n",
    "    else:\n",
    "        print(\"Fail to reject the null hypothesis: There are no significant risk differences across provinces.\")\n",
    "except Exception as e:\n",
    "    print(f\"Error performing chi-squared test for provinces: {e}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Null Hypothesis: There are no risk differences between zip codes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chi-squared test for zip codes: p-value = 1.0\n",
      "Fail to reject the null hypothesis: There are no significant risk differences between zip codes.\n"
     ]
    }
   ],
   "source": [
    "# Null Hypothesis: There are no risk differences between zip codes\n",
    "try:\n",
    "    zip_code_p_value = analyzer.chi_squared_test('PostalCode', 'TotalClaims')\n",
    "    print(f\"Chi-squared test for zip codes: p-value = {zip_code_p_value}\")\n",
    "    if zip_code_p_value < 0.05:\n",
    "        print(\"Reject the null hypothesis: There are significant risk differences between zip codes.\")\n",
    "    else:\n",
    "        print(\"Fail to reject the null hypothesis: There are no significant risk differences between zip codes.\")\n",
    "except Exception as e:\n",
    "    print(f\"Error performing chi-squared test for zip codes: {e}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Null Hypothesis: There are no significant margin (profit) differences between zip codes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chi-squared test for zip codes (profit margin): p-value = 0.0\n",
      "Reject the null hypothesis: There are significant margin (profit) differences between zip codes.\n"
     ]
    }
   ],
   "source": [
    "# Null Hypothesis: There are no significant margin (profit) differences between zip codes\n",
    "try:\n",
    "    profit_margin_p_value = analyzer.chi_squared_test('PostalCode', 'TotalPremium')\n",
    "    print(f\"Chi-squared test for zip codes (profit margin): p-value = {profit_margin_p_value}\")\n",
    "    if profit_margin_p_value < 0.05:\n",
    "        print(\"Reject the null hypothesis: There are significant margin (profit) differences between zip codes.\")\n",
    "    else:\n",
    "        print(\"Fail to reject the null hypothesis: There are no significant margin (profit) differences between zip codes.\")\n",
    "except Exception as e:\n",
    "    print(f\"Error performing chi-squared test for profit margins between zip codes: {e}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Null Hypothesis: There are no significant risk differences between women and men"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chi-squared test for gender: p-value = 1.0\n",
      "Fail to reject the null hypothesis: There are no significant risk differences between women and men.\n"
     ]
    }
   ],
   "source": [
    "# Null Hypothesis: There are no significant risk differences between women and men\n",
    "try:\n",
    "    gender_p_value = analyzer.chi_squared_test('Gender', 'TotalClaims')\n",
    "    print(f\"Chi-squared test for gender: p-value = {gender_p_value}\")\n",
    "    if gender_p_value < 0.05:\n",
    "        print(\"Reject the null hypothesis: There are significant risk differences between women and men.\")\n",
    "    else:\n",
    "        print(\"Fail to reject the null hypothesis: There are no significant risk differences between women and men.\")\n",
    "except Exception as e:\n",
    "    print(f\"Error performing chi-squared test for gender: {e}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
